<template>
  <div id="globalHeader">
    <a-row :wrap="false">
      <a-col flex="250px">
        <div class="title-bar">
          <img class="logo" src="@/assets/logo.png" alt="logo" />
          <div class="title">北方民族大学学生中心</div>
        </div>
      </a-col>
      <a-col flex="auto">
        <a-menu
          v-model:selectedKeys="current"
          mode="horizontal"
          :items="items"
          @click="doMenuClick"
        />
      </a-col>
      <a-col flex="60px">
        <div class="user-login-status">
          <div v-if="loginUserStore.loginUser.id">
            {{ loginUserStore.loginUser.username ?? "未定义用户" }}
          </div>
          <div v-else>
            <a-button type="primary" block>登录</a-button>
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script lang="ts" setup>
import { h, ref } from "vue";
import {
  MailOutlined,
  AppstoreOutlined,
  SettingOutlined,
} from "@ant-design/icons-vue";
import { MenuProps } from "ant-design-vue";
import { useRouter } from "vue-router";
import { useUserLoginStore } from "@/store/useUserLoginStore";

const loginUserStore = useUserLoginStore();
const router = useRouter();
//点击菜单跳转后的事件
const doMenuClick = ({ key }: { key: string }) => {
  router.push({
    path: key,
  });
};
const current = ref<string[]>(["mail"]);
router.afterEach((to) => {
  current.value = [to.path];
});
const items = ref<MenuProps["items"]>([
  {
    key: "/",
    icon: () => h(MailOutlined),
    label: "首页",
    title: "首页",
  },
  {
    key: "/user/login",
    icon: () => h(AppstoreOutlined),
    label: "用户登录",
    title: "用户登录",
  },
  {
    key: "/user/register",
    icon: () => h(SettingOutlined),
    label: "用户注册",
    title: "用户注册",
  },
  {
    key: "/admin/userManage",
    icon: () => h(SettingOutlined),
    label: "用户管理",
    title: "用户管理",
  },
  {
    key: "others",
    label: h(
      "a",
      {
        href: "https://blog.csdn.net/suhuixiaoxin?spm=1000.2115.3001.5343",
        target: "_blank",
      },
      "我的博客"
    ),
    title: "我的博客",
  },
]);
</script>
<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}

.title {
  color: black;
  font-size: 18px;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
</style>
